import { SpriteFrame } from "cc";
import ResManager from "../common/ResManager";
import { TotemConfig, em_Effect_Comm } from "../settings/const";

class Effect {
    /**配置项'em_Effect_Comm' */
    type: number
    /**配置项'em_Effect_Comm'类型 */
    mode: number
    /**配置项'em_Effect_Comm'名称 */
    name: string
    /**配置项'em_Effect_Comm'加成 */
    addion: number
}
export class TreaIng {
    /**宝物编号 */
    id: number
    /**宝物名称 */
    name: string
    /**宝物描述++ */
    desc: string
    /**宝物buff编号+提成 */
    effect: string
    /**宝物buff加成详情 */
    effectType: Effect
    /**宝物 grade属性*/
    grade: number
    /**洗练所需钻石 */
    diamond: number
    /**正在探险数据 */
    static EsListVal: any;
    /**宝物库存index */
    index: number;


    /**
    * 根据服务端的数据，来创建宝物库存
    * @param arr 
    * @returns 
    */
    static createByTreaIngObj(arr): TreaIng[] {
        let list: TreaIng[] = []
        arr.forEach((e, i) => {
            let v = new TreaIng()
            let d = TotemConfig[e.id + e.type]
            let c = d.effect.split(',')[0]
            for (let key in em_Effect_Comm) {
                let value = em_Effect_Comm[key]
                if (value.type == c) {
                    let e = new Effect()
                    e.type = value.type
                    e.name = value.name
                    e.mode = value.mode
                    e.addion = d.effect.split(',')[1]
                    v.effectType = e
                }
            }
            v.index = i
            v.id = d.id
            v.name = d.name

            v.desc = d.desc
            v.effect = d.effect
            v.grade = d.grade
            v.diamond = d.diamond
            list.push(v)
        });
        return list
    }

    async getTreaIngImg(): Promise<SpriteFrame>{
        let img = (this.id + '').substring(0, 4)
        return ResManager.instance.loadAssetByUrl<SpriteFrame>(`totemImg/${img}/spriteFrame`)
    }

}

